// 硬件IIC
#ifndef __BSP_IIC_H
#define __BSP_IIC_H

#include "../../imx6ul/imx6ul.h"
#include "../delay/bsp_delay.h"
#include "../gpio/bsp_gpio.h"
#include "../../stdio/include/stdio.h"

// 方向控制
#define SCL_OUT_MODE() (GPIO1->GDIR |=(0x1<<30))
#define SDA_OUT_MODE() (GPIO1->GDIR |=(0x1<<31))
#define SDA_IN_MODE() (GPIO1->GDIR &=~(0x1<<31))
#define HIGH 1
#define LOW 0
// 电平状态
#define SDA_INPUT_LEVEL() ((GPIO1->DR & (0x1<<31))?HIGH:LOW )
#define SDA_OUTPUT_LEVEL(level) do{GPIO1->DR &=~(0x1<<31);GPIO1->DR |=(level << 31);}while(0)
#define SCL_OUTPUT_LEVEL(level) do{GPIO1->DR &=~(0x1<<30);GPIO1->DR |=(level << 30);}while(0)




#define IIC_DELAY_MS(x) delay_ms(x)

void IIC_GPIO_Init(void);
extern void IIC_Start();
extern void IIC_Stop();
extern void IIC_Write_Data(uint_fast8_t data);
extern uint8_t IIC_Read_Data();
extern void IIC_Write_ACK();
extern void IIC_Write_NACK();
extern int IIC_Read_ACK();

#endif
